home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / dxlib50.zip / MICROSOF.ZIP / EXAMP2.C < prev    next >
C/C++ Source or Header  |  1995-02-11  |  2KB  |  54 lines

  1. #include <stdio.h>
  2. #include <xlib.h>
  3. #define som _emit 0x66               /*Switch operand mode*/
  4. #define sam _emit 0x67               /*Switch address mode*/
  5. unsigned long __far getextmem(unsigned long address);
  6.  
  7. int goterr = 0;                      /*Error flag*/
  8.  
  9. void main(void)
  10. {
  11.   unsigned long l, xaddress;
  12.  
  13.   l = INITXLIB();                    /*Initialize XLIB*/
  14.   if(l != 0)                         /*See if an error occurred*/
  15.   {
  16.     printf("Library initialization error:  %lX\n",l);
  17.     return;
  18.   }
  19.  
  20.   xaddress = 0x100000;               /*Read first dword in 2ond meg*/
  21.   l = getextmem(xaddress);           /*See if an error occurred*/
  22.   if(goterr != 0)
  23.   {
  24.     printf("Inline mode-switch error:  %lX\n",l);
  25.     return;
  26.   }
  27.   printf("[%lX] = %lX\n",xaddress,l);
  28. }
  29.  
  30. unsigned long __far getextmem(unsigned long address)
  31. {
  32.   __asm
  33.   {
  34.     som                             ;mov  eax,[bp+6]
  35.     mov       ax,[bp+6]             ;  ""
  36.     call      INLINEPM              ;Switch to 16-bit protected mode
  37.     jc        error                 ;Error code in ax
  38.     mov       ds,es:FLATDSEL        ;Switch to flat data model
  39.     sam                             ;push dword ptr [eax]
  40.     som                             ;  ""
  41.     _emit     0ffh                  ;  ""
  42.     _emit     030h                  ;  ""
  43.     pop       ax                    ;Return address contents in dx:ax
  44.     pop       dx
  45.     call      es:INLINERMPTR        ;Switch back to real mode by calling
  46.     jmp       done                  ;INLINERM indirect.  A direct call would
  47.                                     ;load cs with an invalid value.
  48. error:
  49.     xor       dx,dx                 ;Return error code in dx:ax
  50.     inc       goterr                ;Set error flag
  51. done:
  52.   }
  53. }
  54.